<template>
	<view>
		<template v-if="mode === 'preview'">
			<view class="address-preview">
				<view class="info">
					<view class="address x-text-multi">
						{{getAddressDesc(address.addressName, address.addressDetail)}}
					</view>
					<view class="detail">
						<span class="default" v-if="address.defaultAddress">默认</span>
						<span class="name"
							v-if="address.receiptName && address.receiptName.length>0">{{address.receiptName}}</span>
						<span class="contact" v-if="address.mobile && address.mobile.length>0">{{address.mobile}}</span>
					</view>
				</view>
			</view>
		</template>
		<template v-else>
			<navigator v-if="address && address.id" :url="`/pages/mine/address/index?isSelected=${true}`"
				class="address-bar">
				<view class="info">
					<view class="address x-text-multi">
						{{getAddressDesc(address.addressName, address.addressDetail)}}
					</view>
					<view class="detail">
						<span class="default" v-if="address.defaultAddress">默认</span>
						<span class="name"
							v-if="address.receiptName && address.receiptName.length>0">{{address.receiptName}}</span>
						<span class="contact" v-if="address.mobile && address.mobile.length>0">{{address.mobile}}</span>
					</view>
				</view>

				<view class="arrow">
					<u-icon name="arrow-right" color="xIconColor()" size="10"></u-icon>
				</view>
			</navigator>
			<navigator v-else :url="`/pages/mine/address/index?isSelected=${true}`" hover-class="none"
				class="address-none">
				<view class="plus">
					<u-icon name="plus" color="xIconColor()" size="10"></u-icon>
				</view>
				<view>收货地址</view>
				<view class="arrow">
					<u-icon name="arrow-right" color="xIconColor()" size="10"></u-icon>
				</view>
			</navigator>
		</template>



	</view>
</template>

<script>
	import {
		ThemeMixin
	} from '@/mixins/theme/xThemeMixin.js'

	export default {
		mixins: [ThemeMixin],
		props: {
			address: {
				type: Object,
				default: null,
			},
			mode: {
				type: String,
				default: "", //可选值 'preview', 可用于订单详情
			}
		},
		data() {
			return {

			}
		},
		methods: {
			getAddressDesc(addressName, addressDetail) {
				if (!addressName || addressName?.length <= 0) {
					return ''
				}
				let result = addressName.replace(/,/g, '') + addressDetail
				return result;
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/mixins/theme/xTheme.scss";

	.address-preview {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		margin: 20rpx;
		background: white;
	}

	.address-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;


		.arrow {
			display: flex;
			align-items: center;
		}
	}

	.info {

		.address {
			font-size: 23rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000000;
			line-height: 33rpx;
		}

		.detail {
			display: flex;
			margin-top: 15rpx;

			.default {
				width: 46rpx;
				height: 33rpx;
				font-size: 23rpx;
				font-family: PingFang-SC-Medium;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 33rpx;
				background-color: #{$x-theme-color}#{$x-theme-alpha};
				padding: 2rpx 4rpx;
				border-radius: 6rpx;
				margin-right: 4rpx;
			}

			.name {
				font-size: 23rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #8E8E8E;
				line-height: 33rpx;
				margin-right: 4rpx;
			}

			.contact {
				font-size: 23rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #8E8E8E;
				line-height: 33rpx;
			}
		}
	}


	.address-none {
		height: 120rpx;
		border-bottom: 2rpx dashed #515151;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;

		.plus {
			font-size: 40rpx;
			font-weight: bold;
			margin-right: 20rpx;
		}

		.arrow {
			position: absolute;
			right: 20rpx;
			font-size: 40rpx;
			font-weight: bold;
			margin-right: 20rpx;
		}
	}
</style>